<?xml version="1.0" encoding="UTF-8"?>
<!-- 
 Copyright (C) 2014 - 2016 - Open Source Geospatial Foundation. All rights reserved.
 This code is licensed under the GPL 2.0 license, available at the root
 application directory.
 -->
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
    <bean id="wpsCoreExtension" class="org.geoserver.platform.ModuleStatusImpl">
      <constructor-arg index="0" value="gs-wps-core"/>
      <constructor-arg index="1" value="GeoServer Web Processing Service Core"/>
    </bean>
	<bean id="wpsFactoryExtension" class="org.geoserver.wps.WPSFactoryExtension"/>
	
    <!-- depend on the process factory so we can properly initialize the WPSInfo object with the 
        appropriate factory/group info-->
    <bean id="wpsServiceLoader" class="org.geoserver.wps.WPSXStreamLoader" 
        depends-on="geoserverProcessFactory, deprecatedProcessFactory">
        <constructor-arg ref="resourceLoader"/>
    </bean>

    <!-- TODO: remove this thing -->    
    <bean id="wpsServiceLegacyLoader" class="org.geoserver.wps.WPSLegacyLoader"/>

    <bean id="wpsLifecycleHandler" class="org.geoserver.wps.WPSLifecycleHandler">
      <constructor-arg ref="geoServer"></constructor-arg>
    </bean>
    
    <!-- Resource manager -->
    <bean id="wpsResourceManager" class="org.geoserver.wps.resource.WPSResourceManager">
        <constructor-arg ref="resourceLoader"/>
    </bean>

    <!--  Execution manager, the thing that actually orchestrates the process execution -->
    <bean id="executionManager" class="org.geoserver.wps.executor.WPSExecutionManager">
        <constructor-arg ref="geoServer" />
        <constructor-arg ref="wpsResourceManager" />
        <constructor-arg ref="processStatusTracker"/>
    </bean>    
    
    <!-- The default process runner, others may be around -->
    <bean id="defaultProcessManager" class="org.geoserver.wps.executor.DefaultProcessManager">
      <constructor-arg ref="wpsResourceManager"/>
      <property name="maxAsynchronousProcesses" value="10"/>
      <property name="maxSynchronousProcesses" value="10"/>
    </bean>
    
    <bean id="processStatusTracker" class="org.geoserver.wps.executor.ProcessStatusTracker"/>

    <!-- WPS Service -->
    <bean id="wpsServiceTarget" class="org.geoserver.wps.DefaultWebProcessingService">
        <constructor-arg ref="geoServer" />
        <constructor-arg ref="executionManager" />
        <constructor-arg ref="wpsResourceManager" />
        <constructor-arg ref="processStatusTracker" />
    </bean>
    
    <bean id="wpsLogger" class="org.geoserver.ows.util.EMFLogger">
      <constructor-arg type="java.lang.String" value="org.geoserver.wps"/>
    </bean>
    <bean id="wpsService" class="org.springframework.aop.framework.ProxyFactoryBean">
      <property name="proxyInterfaces">
        <value>org.geoserver.wps.WebProcessingService</value>
      </property>
      <property name="interceptorNames">
        <list>
          <value>wpsLogger</value>
          <value>wpsServiceInterceptor*</value>
          <value>wpsServiceTarget</value>        
        </list>
      </property>
    </bean>

    <!-- Service Descriptor(s) -->
    <bean id="wpsService-1.0.0" 
        class="org.geoserver.platform.Service">
        <constructor-arg index="0" value="wps" />
        <constructor-arg index="1" ref="wpsService" />
        <constructor-arg index="2" value="1.0.0" />
        <constructor-arg index="3">
            <list>
              <value>GetCapabilities</value>
              <value>DescribeProcess</value>
              <value>Execute</value>
              <value>Dismiss</value>
              <value>GetExecutionStatus</value>
              <value>GetExecutionResult</value>
              <value>GetExecutions</value>
            </list>
        </constructor-arg>
    </bean>

    <!-- KVP Parsers -->
    <bean id="wpsDescribeIdentifierKvpParser"
        class="org.geoserver.wps.kvp.DescribeIdentifierKvpParser" />
    <bean id="wpsExecuteIdentifierKvpParser"
        class="org.geoserver.wps.kvp.ExecuteIdentifierKvpParser" />
    
    <!-- KVP Request Readers -->
    <bean id="wpsGetCapabilitiesKvpReader"
        class="org.geoserver.wps.kvp.GetCapabilitiesKvpRequestReader" />
    <bean id="wpsDescribeProcessKvpReader"
        class="org.geoserver.wps.kvp.DescribeProcessKvpRequestReader" />
    <bean id="executeKvpRequestReader" class="org.geoserver.wps.kvp.ExecuteKvpRequestReader"/>
    <bean id="statusKvpRequestReader" class="org.geoserver.wps.kvp.GetExecutionStatusKvpRequestReader"/>
    <bean id="resultKvpRequestReader" class="org.geoserver.wps.kvp.GetExecutionResultKvpRequestReader"/>
    <bean id="dismissKvpRequestReader" class="org.geoserver.wps.kvp.DismissKvpRequestReader"/>
    <bean id="wpsGetExecutionsKvpRequestReader" class="org.geoserver.wps.kvp.GetExecutionsKvpRequestReader"/>
    
    <!-- XML Configuration -->
    <bean id="wpsXmlConfiguration-1.0.0"
        class="org.geoserver.wps.xml.WPSConfiguration" >
    </bean>

    <!-- XML Readers -->
    <bean id="wpsXmlReader-1.0.0"
        class="org.geoserver.wps.xml.v1_0_0.WpsXmlReader" abstract="true">
        <constructor-arg ref="wps" />
        <constructor-arg ref="wpsXmlConfiguration-1.0.0" />
    </bean>
    <bean id="wpsGetCapabilitiesXmlReader-1.0.0"
        class="org.geoserver.wps.xml.v1_0_0.WpsXmlReader">
        <constructor-arg index="0" value="GetCapabilities" />
        <constructor-arg index="1" value="1.0.0" />
        <constructor-arg index="2" ref="wpsXmlConfiguration-1.0.0" />
        <constructor-arg index="3" ref="entityResolverProvider" />
    </bean>
    <bean id="wpsDescribeProcessXmlReader-1.0.0"
        class="org.geoserver.wps.xml.v1_0_0.WpsXmlReader">
        <constructor-arg index="0" value="DescribeProcess" />
        <constructor-arg index="1" value="1.0.0" />
        <constructor-arg index="2" ref="wpsXmlConfiguration-1.0.0" />
        <constructor-arg index="3" ref="entityResolverProvider" />
    </bean>
    <bean id="wpsExecuteXmlReader-1.0.0"
        class="org.geoserver.wps.xml.v1_0_0.WpsXmlReader">
        <constructor-arg index="0" value="Execute" />
        <constructor-arg index="1" value="1.0.0" />
        <constructor-arg index="2" ref="wpsXmlConfiguration-1.0.0" />
        <constructor-arg index="3" ref="entityResolverProvider" />
    </bean>
 

    <!-- HTTP URL Mapping -->
	<bean id="wpsURLMapping" class="org.geoserver.ows.OWSHandlerMapping">
		<constructor-arg ref="catalog"/>
        <property name="alwaysUseFullPath" value="true" />
        <property name="mappings">
            <props>
                <prop key="/wps">dispatcher</prop>
                <prop key="/wps/*">dispatcher</prop>
            </props>
        </property>
    </bean>
    
    <!-- responses -->
    <bean id="wpsCapabilitiesResponse" class="org.geoserver.wps.response.WPSObjectEncodingResponse">
      <constructor-arg index="0" value="net.opengis.wps10.WPSCapabilitiesType"/>
      <constructor-arg index="1" value="Capabilities"/>
      <constructor-arg index="2" value="org.geoserver.wps.xml.WPSConfiguration"/> 
    </bean>
    <bean id="wpsDescribeProcessResponse" class="org.geoserver.wps.response.WPSObjectEncodingResponse">
      <constructor-arg index="0" value="net.opengis.wps10.ProcessDescriptionsType"/>
      <constructor-arg index="1" value="ProcessDescriptions"/>
      <constructor-arg index="2" value="org.geoserver.wps.xml.WPSConfiguration"/> 
    </bean>
    <bean id="wpsExecuteResponse" class="org.geoserver.wps.response.ExecuteProcessResponse">
      <constructor-arg index="0" value="net.opengis.wps10.ExecuteResponseType"/>
      <constructor-arg index="1" value="ExecuteResponse"/>
      <constructor-arg index="2" value="org.geoserver.wps.xml.WPSConfiguration"/>
    </bean>
    <bean id="wpsStoredResourceResponse" class="org.geoserver.wps.response.StoredResourceResponse">
      <constructor-arg index="0" ref="wpsResourceManager"/>
    </bean>
    <bean id="wpsExecutionsResponse" class="org.geoserver.wps.response.GetExecutionsResponse" scope="prototype"/>
    
    <!-- Exception handler, we need to output ows 1.1 exceptions -->
    <bean id="wpsExceptionHandler" class="org.geoserver.ows.OWS11ServiceExceptionHandler">
      <constructor-arg index="0">
        <list>
          <ref bean="wpsService-1.0.0" />
        </list>
      </constructor-arg>
    </bean>
    
    <!-- The PPIO that need to be registered into SPI because of their dependencies -->
    <bean id="geoTiffPPIO" class="org.geoserver.wps.ppio.GeoTiffPPIO">
      <constructor-arg ref="wpsResourceManager"/>
    </bean>
    <bean id="arcGridPPIO" class="org.geoserver.wps.ppio.ArcGridPPIO">
      <constructor-arg ref="wpsResourceManager"/>
    </bean>
    <bean id="coveragePngPPIO" class="org.geoserver.wps.ppio.CoveragePPIO.PNGPPIO"/>
    <bean id="coverageJpegPPIO" class="org.geoserver.wps.ppio.CoveragePPIO.JPEGPPIO"/>
    <bean id="shapeZipPPIO" class="org.geoserver.wps.ppio.ShapeZipPPIO">
      <constructor-arg ref="wpsResourceManager"/>
      <constructor-arg ref="geoServer"/>
      <constructor-arg ref="catalog"/>
      <constructor-arg ref="resourceLoader"/>
    </bean>
    <bean id="interpolationPPIO" class="org.geoserver.wps.ppio.InterpolationPPIO" />
    <bean id="sldStylePPIO" class="org.geoserver.wps.ppio.SLDStylePPIO" />
    <bean id="urlPPIO" class="org.geoserver.wps.ppio.URLPPIO" />
    <bean id="jaitoolsRangePPIO" class="org.geoserver.wps.ppio.JAIToolsRangePPIO"/>
    <bean id="rawDataPPIO" class="org.geoserver.wps.ppio.RawDataPPIO">
      <constructor-arg ref="wpsResourceManager" />
    </bean>
    <bean id="CSVPPIO" class="org.geoserver.wps.ppio.CSVPPIO">
      <constructor-arg ref="wpsResourceManager" />
    </bean>
    <bean id="geoJsonGeometriesPPIO" class="org.geoserver.wps.ppio.GeoJSONPPIO.Geometries">
        <constructor-arg ref="geoServer"/>
    </bean>
    <bean id="geoJsonFeatureCollectionPPIO" class="org.geoserver.wps.ppio.GeoJSONPPIO.FeatureCollections">
        <constructor-arg ref="geoServer"/>
    </bean>
    <bean id="classificationStatsPPIO" class="org.geoserver.wps.gs.ClassificationStatsPPIO"/>

    <!-- Register the GeoServer factory and processes -->
    <bean id="geoserverProcessFactory" class="org.geoserver.wps.jts.SpringBeanProcessFactory">
      <constructor-arg index="0" value="GeoServer specific processes"/>
      <constructor-arg index="1" value="gs"/>
      <constructor-arg index="2" value="org.geoserver.wps.gs.GeoServerProcess"/>
    </bean>
    <bean id="importProcess" class="org.geoserver.wps.gs.ImportProcess">
      <constructor-arg index="0" ref="catalog"/>
    </bean>
    
    <bean id="pagedUniqueProcess" class="org.geoserver.wps.gs.PagedUniqueProcess">
    </bean>
    <bean id="pagedUniquePPIO" class="org.geoserver.wps.gs.PagedUniqueProcessPPIO"/>

    <bean id="aggregateProcessResultPPIO" class="org.geoserver.wps.gs.AggregateProcessPPIO"/>
    <bean id="aggregateProcessResultJSONPPIO" class="org.geoserver.wps.gs.AggregateProcessJSONPPIO"/>

    <bean id="storeCoverageProcess" class="org.geoserver.wps.gs.StoreCoverage" >
      <constructor-arg index="0" ref="wpsResourceManager"></constructor-arg>
    </bean>

    <bean id="georectifyConfiguration" class="org.geoserver.wps.gs.GeorectifyConfiguration" /> 
    <bean id="georectifyCoverage" class="org.geoserver.wps.gs.GeorectifyCoverage">
    	<property name="config" ref="georectifyConfiguration" /> 
      <property name="resourceManager" ref="wpsResourceManager" />
    </bean>
    
    <bean id="getFullCoverage" class="org.geoserver.wps.gs.GetFullCoverage">
      <constructor-arg index="0" ref="catalog"/>
    </bean>
    
    <!--
    Factory for deprecated processes 
    -->
    <bean id="deprecatedProcessFactory" class="org.geoserver.wps.DeprecatedProcessFactory" lazy-init="false">
    </bean>

    <!-- 
       ==================================================================
       Deal with temporary files
       ==================================================================
    -->
    
    <!-- Map dispatcher in order to publish the wcsTempStorage directory -->
    <bean id="wpsTempDirDispatcherMapping"
      		class="org.geoserver.ows.OWSHandlerMapping">
  	  <constructor-arg ref="catalog"/>
      <property name="alwaysUseFullPath" value="true" />
      <property name="mappings">
        <props>
          <prop key="/temp/**">filePublisher</prop>
        </props>
      </property>
    </bean>
  
    <!-- Temp storage cleanup -->
    <bean id="wpsStorageCleaner" class="org.geoserver.wps.WPSStorageCleaner">
      <constructor-arg index="0" ref="wpsResourceManager" />
      <constructor-arg index="1" ref="processStatusTracker" />
    </bean>
  
    <!-- Definition of how often the scheduled task runs -->
    <bean id="wpsStorageCleanerTask"
      class="org.springframework.scheduling.concurrent.ScheduledExecutorTask">
      <!-- wait 10 seconds before starting repeated execution -->
      <property name="delay" value="10000" />
      <!-- run every 60 seconds -->
      <property name="period" value="60000" />
      <property name="runnable" ref="wpsStorageCleaner" />
    </bean>
  
    <!--
      And finally the class that instantiates the scheduled tasks and
      makes them run
    -->
    <bean id="wpstimerFactory" class="org.springframework.scheduling.concurrent.ScheduledExecutorFactoryBean"
      lazy-init="false">
      <property name="scheduledExecutorTasks">
        <list>
          <ref bean="wpsStorageCleanerTask" />
        </list>
      </property>
      <property name="daemon" value="true" />
    </bean>
    
    <!-- Configures some WPS subsystems with the current config values and keeps them up to date -->
    <bean id="wpsInitializer" class="org.geoserver.wps.WPSInitializer">
      <constructor-arg index="0" ref="executionManager"/>
      <constructor-arg index="1" ref="defaultProcessManager"/>
      <constructor-arg index="2" ref="wpsStorageCleaner"/>
      <constructor-arg index="3" ref="wpsResourceManager"/>
      <constructor-arg index="4" ref="resourceLoader"/>
    </bean>

    <!-- The uber-process factory used by GeoServer -->
    <bean id="wpsProcessors" class="org.geoserver.wps.process.GeoServerProcessors" lazy-init="false"/>
    
    <!-- The default process filters -->
    <bean id="unsupportedParameterTypeProcessFilter" class="org.geoserver.wps.UnsupportedParameterTypeProcessFilter" lazy-init="false"/>
    <bean id="configuredProcessesFilter" class="org.geoserver.wps.DisabledProcessesSelector" lazy-init="false"/>

    <bean id="wpsLocalWorkspaceURLManger" class="org.geoserver.ows.LocalWorkspaceURLMangler">
      <constructor-arg value="wps"/>
    </bean>
    
    <bean id="executionIdThreadLocalTransfer" class="org.geoserver.wps.resource.ExecutionIdThreadLocalTransfer">
      <constructor-arg ref="wpsResourceManager"/>
    </bean>

    <bean id="coverageResourceListener" class="org.geoserver.wps.resource.CoverageResourceListener" lazy-init="false">
      <constructor-arg ref="wpsResourceManager"/>
      <constructor-arg ref="coverageCleaner"/>
    </bean>
    
    <!-- Input limits support -->
    <bean id="processLimitsFilter" class="org.geoserver.wps.validator.ProcessLimitsFilter" lazy-init="false">
      <constructor-arg index="0" ref="geoServer"/>
    </bean>
    <!-- Size estimation portion of limits -->
    <bean id="objectSizeEstimators" class="org.geoserver.wps.validator.ObjectSizeEstimators" lazy-init="false"/>
    <bean id="featureSizeEstimators" class="org.geoserver.wps.validator.FeatureSizeEstimator"/>
    <bean id="rasterSizeEstimators" class="org.geoserver.wps.validator.RasterSizeEstimator"/>
    <bean id="rawDataSizeEstimator" class="org.geoserver.wps.validator.RawDataSizeEstimator"/>
    <bean id="geometrySizeEstimator" class="org.geoserver.wps.validator.GeometrySizeEstimator"/>
    <bean id="processStartupFilter" class="org.geoserver.wps.executor.ProcessStartupFilter"/>
</beans>
